"""
logging模块的使用
"""

import logging


# 日志配置字典
logging_config = {
    "version": 1.0,
    "disable_existing_loggers": False,  # 是否禁用已经存在的日志器
    # 日志格式
    "formatters": {
        "standard": {
            "format": "%(asctime)s - %(name)s - [%(pathname)s:%(lineno)d] - %(levelname)s - %(message)s"
        },
        "simple": {"format": "%(levelname)s - %(message)s"},
        "test": {"format": "%(asctime)s - %(name)s - %(message)s"},
    },
    # 日志处理器
    "handlers": {
        "console": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "standard",
        },
        "file": {
            "level": "DEBUG",
            "class": "logging.handlers.RotatingFileHandler",
            "filename": "logs/my.log",
            "maxBytes": 1024 * 1024 * 5,
            "backupCount": 5,
            "formatter": "standard",
            "encoding": "utf8",
        },
    },
    # 日志管理器
    "loggers": {
        "": {"handlers": ["console", "file"], "level": "DEBUG", "propagate": True},
    },
}


logging.debug("调试日志")
logging.info("信息日志")
logging.warning("警告日志")
logging.error("错误日志")
logging.critical("严重错误日志")


# # 日志基本配置
# logging.basicConfig(
#     # 日志级别
#     level=logging.DEBUG,  # 日志级别：DEBUG:10、INFO:20、WARNING:30、ERROR:40、CRITICAL:50
#     # 日志格式
#     format="%(asctime)s - %(name)s - [%(pathname)s:%(lineno)d] - %(levelname)s - %(message)s",
#     # asctime的时间格式
#     datefmt="%Y-%m-%d %H:%M:%S",
#     # 日志文件名
#     filename="my.log",  # 不配置则输出到控制台
#     # 日志文件最大大小
#     filemode="w",
#     # 日志文件保存数量
#     maxBytes=1024 * 1024 * 5,
#     # 日志文件保存数量
#     backupCount=5,
#     # 是否在控制台输出日志
#     stream=None,
# )
